function [F, G] = grid_search(param, const, Pi0, Pi1, ExportCutoffQ, ExportProbQ)

    % lnZ for each Q
    matrix_lnZ = const.k0*const.lnzQ -log(param.sigma*const.gamma);
    
    % EPi for each Q
    matrix_NetPi = exp(matrix_lnZ).*kron(ones(param.Nf,1),Pi1-Pi0).*ExportProbQ...
        - exp(param.mu_E+1/2*param.sigma_E^2).*normcdf(ExportCutoffQ-param.sigma_E);
    matrix_EPi = kron(ones(param.Nf,1),Pi0) + matrix_NetPi./exp(matrix_lnZ);
    
    % check
    if min(min(matrix_NetPi.*(ExportProbQ>0.0001)))<0
        disp('error: payoff')
        [min(min(matrix_NetPi))]
    end    
    
    % payoff for each Q
    matrix_payoff = matrix_lnZ + log(matrix_EPi);
    
    % grid search
    [payoff_opt, q_opt_index] = max(matrix_payoff, [], 2);           
    
    % return
    F = q_opt_index;
    G = payoff_opt;
    
end